package great.project.common.http;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

/**
 *  <div  style="border:2px solid none;margin:20px;padding:15px;font-size:24px;text-align:center;color:aqua;">
 *
 *
 *
 *  </div>
 * @author v_zhangshun01
 * @date 2021/9/29 2:41 下午
 */
@Getter
@Setter
@Builder
@ToString
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
@JsonInclude(JsonInclude.Include.NON_NULL)
public final class ResponseMessage<T> {

    /**
     * 200 --- ok
     * 201 ---
     */
    private ResponseCode code;

    private String msg;

    private T data;

    public static ResponseMessage<String> ok(String msg){
        return ok(msg , null);
    }


    public static <T> ResponseMessage<T> ok(T data){
        return ok(null , data);
    }

    public static <T> ResponseMessage<T> ok(String msg , T data){
        return ResponseMessage.<T>builder()
                .code(ResponseCode.OK)
                .msg(msg)
                .data(data)
                .build();
    }


    public static ResponseMessage<String> failure(String msg){
        return failure(msg , null);
    }


    public static <T> ResponseMessage<T> failure(T data){
        return failure(null , data);
    }

    public static <T> ResponseMessage<T> failure(String msg , T data){
        return ResponseMessage.<T>builder()
                .code(ResponseCode.FAILED)
                .msg(msg)
                .data(data)
                .build();
    }


}
